define(['vue','agile'], function(Vue,A){  
	var templatestr='<div><ul  class="grid size54 border" data-rowspace="12" data-col="2" >\
				        <li v-for="(item,index) in list"  >\
				        	<i v-if="item.isdelete&&editmodel" class="icon icon-clear color-9 "\
				        	 style="font-size:20px;height:20px;width:20px;padding:5px"></i>\
				        	<img :src="item.imgURL" @tap="toggle(index)" style="height:90px;width:90px"></img>\
				        </li>\
	    	          </ul>\
	    	          <ul class="grid size54 border" data-rowspace="12" data-col="2" >\
	    	          	<template v-if="!editmodel">\
				        <li @tap="openCamera">\
				        	<i   class="icon icon-camera size24" style="color:#CCCCCC"></i>\
				        	<label class="bold" style="font-size:1em;color:#CCCCCC">拍照</label>\
				        </li>\
				        <li v-if="list.length>0" @tap="editPhoto">\
				        	<i  class="icon icon-rdomore size24" style="color:#CCCCCC"></i>\
				        	<label  class="bold" style="font-size:1em;color:#CCCCCC">编辑</label>\
				        </li>\
	    	          	</template>\
				        <template v-else>\
				        <li @tap="deletePhoto" style="background-color:#FF4040">\
				        	<i class="icon icon-trash  size24" style="color:white"></i>\
				        	<label class="bold" style="font-size:1em;color:white">确认删除</label>\
				        </li>\
				        <li  @tap="editPhoto">\
				        	<i class="icon icon-arrowreply size24" style="color:#CCCCCC"></i>\
				        	<label class="bold" style="font-size:1em;color:#CCCCCC">取消</label>\
				        </li>\
				        </template>\
	    	          </ul><div>';
	  
     // 初始化拍照控件
     var init = function(_selector){
	  var photo_vm = new Vue({
						el:_selector,
						template: templatestr,
						data:{
							list:[],
							editmodel:false,
							time:0
						},
						methods:{
							toggle:function(index){
							  if(!this.editmodel)
							    this.showPic(index)
							  else
							    this.select(index)
							   return false
							},
							showPic:function(index){
							  //点击打开图片浏览器外部重写可以调用AL的控件实现
							},
							select:function(index){
			                   //编辑模式下选择图片
			                   //部分安卓机子会出现双触发，触发间隔小于某值强行取消多触发的事件
			                   var newtime = new Date().getTime()
			                   if (newtime-this.time<250)
			                     return false
			                   this.time = newtime
			                   this.list[index].isdelete = !this.list[index].isdelete
							},
							initlist:function(data){
								this.list=data
							},
							openCamera:function(){
								//打开原生拍照界面需重写
						      return false
							},
							editPhoto:function(){
							 //编辑模式
							  this.editmodel = !this.editmodel
						      return false	
							},
							deletePhoto:function(){
						      var idstr = ""
						      var flag= false
					          for(idx in this.list){
					          	if(this.list[idx].isdelete){
					          	  flag = true
					          	  break
					          	}
					          }
					          if (flag){
					          	//自定义函数
							    this.beforDelete()
							    
							    var oldi = this.list.length
							    for(key in this.list){
							    	if(!this.list[key].isdelete){
							    		this.list.push(this.list[key])
							    	}
							    }
							    this.list.splice(0,oldi)	
							    if(this.list.length==0)
							        this.editmodel = !this.editmodel
							  }	
						      return false	
							},
							beforDelete:function(){
							  //删除图片前的自定义处理函数，外部重写
							  return false	
							},
							refreshScroll:function(){
							  return false
							}
						},
						updated:function(){
							this.$nextTick(function(){ this.refreshScroll()})
						}
					})
	  
	  return photo_vm;
	  
     }
     return {init:init};  
})  
